<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ include file="../session.jsp"%>
<!DOCTYPE html>
<html lang="ko">
  <head>
  	<%@ include file="../head.jsp"%>${alert}
  	<style>
  		.box {
  			width: 50%; height: 50%;
  		}
  		.input-group-addon {
  			background-color: #ffffff;
  			border: 0px;
  		}
  	</style>
  </head>
  <body>
  	<%@ include file="../menu.jsp"%>
	<div class="container">
		<div class="page-header clearfix">
			<h2 class="pull-left">이벤트 관리</h2>
			<div class="pull-right" style="padding-top: 30px">
				<a href="#" id="opensearch" class="btn btn-info">검색조건 펼치기/접기</a>
			</div>
		</div>
		
		<div id="searchdiv">
			<form id="searchUserPouch" class="form-horizontal" role="form" method="get" action="listEvent.do">
				<fieldset>
					<div class="clearfix">
					
						<div class="box pull-left">
							<div class="form-group">
								<label for="boardTitle" class="col-md-2 control-label">이벤트명</label>
								<div class="col-md-9">
									<input type="text" class="form-control" name="boardTitle">
								</div>
							</div>
							
							<div class="form-group">
								<label for="brand" class="col-md-2 control-label">클라이언트</label>
								<div class="col-md-9">
									<select class="form-control" name="brand">
										<option>--- 선택하세요 ---</option>
										<c:forEach items="${brand}" var="brand">
											<option value="${brand.idBrand}">${brand.brandTitle}</option>
										</c:forEach>
									</select>
								</div>
							</div>
						</div>
						
						<div class="box pull-right">
							<div class="form-group">
								<label for="start_date" class="col-md-2 control-label">이벤트기간</label>
								<div class="col-md-9 input-group input-group-sm">
									<input type="date" class="form-control" name="start_date">
									<span class="input-group-addon">~</span>
									<input type="date" class="form-control" name="end_date">
								</div>
							</div>
							
							<div class="form-group">
								<div class="col-md-11">
									<div class="row">
										<div class="col-md-6">
											<button type="submit" class="btn btn-primary btn-block">검색하기</button>
										</div>
										<div class="col-md-6">
											<button type="reset" class="btn btn-warning btn-block">다시작성</button>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
						
				</fieldset>
			</form>
			<hr/>
		</div>
		
		<span class="pull-left" style="margin-bottom:10px;">등록 : ${page.totalArticleCount}건 / 활성 : ${display}건 / 비활성 : ${unDisplay}건</span>
		<div class="table-responsive">
			<table class="table table-striped table-hover">
				<thead>
					<tr class="warning row">
						<th class="text-center col-md-1">이벤트번호</th>
						<th class="text-center col-md-2">등록일</th>
						<th class="text-center col-md-2">이벤트명</th>
						<th class="text-center col-md-2">클라이언트</th>
						<th class="text-center col-md-1">시작일</th>
						<th class="text-center col-md-1">종료일</th>
						<th class="text-center col-md-1">
							<c:choose>
								<c:when test="${sort eq 'isReadCount'}"><a href="listEvent.do?order=isUnReadCount${where}">조회수 ▲</a></c:when>
								<c:otherwise><a href="listEvent.do?order=isReadCount${where}">조회수 ▼</a></c:otherwise>
							</c:choose>
						</th>
						<th class="text-center col-md-1">
							<c:choose>
								<c:when test="${sort eq 'isCommentCount'}"><a href="listEvent.do?order=isUnCommentCount${where}">덧글수 ▲</a></c:when>
								<c:otherwise><a href="listEvent.do?order=isCommentCount${where}">덧글수 ▼</a></c:otherwise>
							</c:choose>
						</th>
						<th class="text-center col-md-1">
							<c:choose>
								<c:when test="${sort eq 'isDisplay'}"><a href="listEvent.do?order=isUnDisplay${where}">전시여부 ▲</a></c:when>
								<c:otherwise><a href="listEvent.do?order=isDisplay${where}">전시여부 ▼</a></c:otherwise>
							</c:choose>
						</th>
					</tr>
				</thead>
				<tbody>
					<c:forEach items="${event}" var="list">
						<tr class="text-center row">
							<td class="col-md-1">${list.idAdminBoard}</td>
							<td class="col-md-2">
								${fn:substring(list.create_date, 0, 4)}-${fn:substring(list.create_date, 4, 6)}-${fn:substring(list.create_date, 6, 8)}
								&nbsp;${fn:substring(list.create_date, 8, 10)}:${fn:substring(list.create_date, 10, 12)}
							</td>
							<td class="col-md-2"><a href="updateEvent.do?id=${list.idAdminBoard}">${list.boardTitle}</a></td>
							<td class="col-md-2">${list.idBrandValue}</td>
							<td class="col-md-1 small">
								${fn:substring(list.start_date, 0, 4)}-${fn:substring(list.start_date, 4, 6)}-${fn:substring(list.start_date, 6, 8)}
								&nbsp;${fn:substring(list.start_date, 8, 10)}:${fn:substring(list.start_date, 10, 12)}
							</td>
							<td class="col-md-1 small">
								${fn:substring(list.end_date, 0, 4)}-${fn:substring(list.end_date, 4, 6)}-${fn:substring(list.end_date, 6, 8)}
								&nbsp;${fn:substring(list.end_date, 8, 10)}:${fn:substring(list.end_date, 10, 12)}
							</td>
							<td class="col-md-1">${list.readCount}</td>
							<td class="col-md-1">${list.comment_count}</td>
							<c:choose>
								<c:when test="${list.isDisplay == 1}">
									<td class="col-md-1">Y
										<a href="listEvent.do?page=${page.nowPage}&id=${list.idAdminBoard}&isDisplay=${list.isDisplay}${where}${order}">
											<button type="button" class="btn btn-xs btn-defalut unDisplay">삭제</button>
										</a>
									</td>
								</c:when>
								<c:otherwise>
									<td class="col-md-1">N
										<a href="listEvent.do?page=${page.nowPage}&id=${list.idAdminBoard}&isDisplay=${list.isDisplay}${where}${order}">
											<button type="button" class="btn btn-xs btn-primary display">승인</button>
										</a>
									</td>
								</c:otherwise>
							</c:choose>
						</tr>
					</c:forEach>
				</tbody>
			</table>
		</div>
		
		<div class="text-center">
			<ul class="pagination">

				<!-- 이전 그룹 -->
				<c:choose>
					<c:when test="${page.startPage > page.pageGroupCount}">
						<li><a href="listEvent.do?page=${page.startPage-1}${where}${order}">&laquo;</a></li>
					</c:when>
					<c:otherwise>
						<li class="disabled"><a href="#">&laquo;</a></li>
					</c:otherwise>
				</c:choose>
				
				<!-- 페이지 번호 -->
				<c:forEach begin="${page.startPage}" end="${page.endPage}" step="1" var="now">
					<c:choose>
						<c:when test="${page.nowPage == now}">
							<li class="active"><a href="#">${now}</a></li>
						</c:when>
						<c:otherwise>
							<li><a href="listEvent.do?page=${now}${where}${order}">${now}</a></li>
						</c:otherwise>
					</c:choose>
				</c:forEach>

				<!-- 다음 그룹 -->
				<c:choose>
					<c:when test="${page.endPage < page.lastGroupFirstPage}">
						<li><a href="listEvent.do?page=${page.endPage+1}${where}${order}">&raquo;</a></li>
					</c:when>
					<c:otherwise>
						<li class="disabled"><a href="#">&raquo;</a></li>
					</c:otherwise>
				</c:choose>

			</ul>
		</div>

	</div>
	<!-- Javascript -->
	<script src="assets/js/jquery.js"></script>
	<script src="assets/js/bootstrap.min.js"></script>
	<script>
		$(function() {
			$("#searchdiv").hide();
			
			$("#opensearch").click(function() {
				$("#searchdiv").toggle();
				return false;
			});
			
			$(".unDisplay").click(function() {
				if (!confirm("정말 비활성처리 하시겠습니까?")) {
					return false;
				}
			});
			
			$(".display").click(function() {
				if (!confirm("정말 승인처리 하시겠습니까?")) {
					return false;
				}
			});
		});
	</script>
  </body>
</html>